﻿
namespace Graphix.Elements
{
    using System.Drawing;
    using SvgNet.SvgGdi;

    public class PiePart : BaseElement
    {
        private float spaceBetweenElements;

        public float Size { get; set; }

        public float StartAngle { get; set; }

        public float SweepAngle { get; set; }

        public float SpaceBetweenElements
        {
            get
            {
                return this.spaceBetweenElements;
            }

            set
            {
                if (value < 0)
                {
                    this.spaceBetweenElements = 0;
                }
                else if (value > 1)
                {
                    this.spaceBetweenElements = 1;
                }
                else
                {
                    this.spaceBetweenElements = value;
                }
            }
        }

        public Color BorderColor { get; set; }

        public override void Draw(IGraphics graphics)
        {
            graphics.FillPie(this.Color, this.Position.X, this.Position.Y, this.Size, this.Size,
                this.StartAngle,
                this.SweepAngle,
                this.Attributes);

            if (this.SpaceBetweenElements > 0)
            {
                graphics.DrawPie(
                    new Pen(this.BorderColor, this.SpaceBetweenElements), this.Position.X,
                    this.Position.Y, this.Size, this.Size,
                    this.StartAngle,
                    this.SweepAngle,
                    this.Attributes);
            }
        }

        public PiePart(float x, float y, float size, float startAngle, float sweepAngle, Brush color = null, float spaceBetweenElements = 0.5f)
            : base(x, y, color)
        {
            this.Size = size;
            this.StartAngle = startAngle;
            this.SweepAngle = sweepAngle;
            this.SpaceBetweenElements = spaceBetweenElements;
        }
    }
}
